package models

// import (
// 	"github.com/gin-gonic/gin"
// )

type Examinee struct {
	Eno       string `gorm:"column:eno"`
	Ename     string `gorm:"column:ename"`
	Sex       string `gorm:"column:sex"`
	Age       string    `gorm:"column:age"`
	Political string `gorm:"column:political"`
	Fresh     string `gorm:"column:fresh"`
	Origin    string `gorm:"column:origin"`
	Record    string `gorm:"column:record"`
	Cname     string `gorm:"column:cname"`
	Category  string `gorm:"column:category"`
}

func GetAllExaminee(examineeParam map[string]interface{}) (error, []Examinee, int64) {
	var examineeData []Examinee
	page := examineeParam["page"].(int)
	pageSize := examineeParam["limit"].(int)
	searchText := examineeParam["searchText"].(string)
	var total int64
	err := db.Table("examinee").Where("eno like ?", "%"+searchText+"%").Order("cname ASC").Count(&total).Find(&examineeData).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, examineeData, total
}

func AddExaminee(examineedata Examinee) (error, Examinee) {
	err := db.Table("examinee").Select("eno", "ename", "sex", "age", "political","fresh","origin","record","cname","category").Create(&examineedata).Error
	return err, examineedata
}

func UpdateExaminee(eno string, examineedata Examinee) (error, Examinee) {
	err := db.Table("examinee").Where("eno = ?", examineedata.Eno).Updates(&examineedata).Error
	return err, examineedata
}

func DeleteExaminee(eno string) (error, Examinee) {
	var examineedata Examinee
	examineedata.Eno = eno
	err := db.Table("examinee").Where("eno = ?", eno).Find(&examineedata).Delete(Examinee{}).Error
	return err, examineedata
}



